import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/ServletDemo1")
public class ServletDemo1 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //获取虚拟目录名称
        String contextPath = req.getContextPath();
        System.out.println(contextPath);

        //获取映射路径
        String servletPath = req.getServletPath();
        System.out.println(servletPath);

        //访问者的ip地址
        String ip = req.getRemoteAddr();
        System.out.println(ip);

        //获取请求消息数据
        String queryString = req.getQueryString();
        System.out.println(queryString);

        //访问URI   虚拟目录名称加映射路径 范围更大
        String uri = req.getRequestURI();
        //URL   绝对路径
        StringBuffer url = req.getRequestURL();

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
